<template>
	<view class="container position-relative">
		<view @click="searchMyPro" class="bg-white searchs text-11 shadow round text-center color" v-if='type==1'>
			筛选
		</view>
		<!--  #ifdef APP-PLUS-->
		<uni-nav-bar fixed='true' @clickLeft='back' statusBar='true' style="width: 100%;">
			<block>
				<view slot='left'>
					<text class="cuIcon-back"></text>

				</view>
				<view v-if='type==1' class="status-center padding-left center bg-F4F4F4  round"
					style="height: 70rpx;margin-left: -30px;">
					<image :src="baseUrl + '/static/search_for.png'" mode="" style="width: 25rpx;height: 25rpx;">
					</image>
					<input type="text" v-model="title" value="" class="text-13 f-grow1 padding-left-sm"
						placeholder="标题" />
				</view>

			</block>

		</uni-nav-bar>
		<!--  #endif -->
		<view class="bg-white">
			<!--  #ifdef   MP-WEIXIN -->
			<kg-custom :isBack="true" bgColor="bg-white">
				<block slot="left">
					<view v-if="type==1"
						class="flex justify-start align-center bg-F4F4F4 padding-left round margin-left-sm"
						style="height: 70rpx;width: 460rpx;">
						<image :src="baseUrl + '/static/search_for.png'" mode="" style="width: 25rpx;height: 25rpx;">
						</image>
						<input type="text" v-model="title" value="" class="text-13 f-grow1 padding-left-sm"
							placeholder="标题" />
					</view>
				</block>
			</kg-custom>
			<!--  #endif -->
			<view class="flex justify-around align-center text-15 text-999 tabs">
				<view class="padding-sm" :class="{on:type==1}" @click="checkType(1)">
					我的上传
				</view>
				<view class="padding-sm" :class="{on:type==2}" @click="checkType(2)">
					我的关注
				</view>
				<view class="padding-sm" :class="{on:type==3}" @click="checkType(3)">
					我的评论
				</view>
				<view class="padding-sm" :class="{on:type==4}" @click="checkType(4)">
					我的报名
				</view>
			</view>
		</view>
		<block v-if='type==1'>
			<view @click="handClick(item.id,item.fileType,item)" class="margin-sm bg-white padding list radius10"
				v-for='(item,index) in list' :key='index'>

				<view class="flex justify-start align-center">
					<image v-if='item.fileType==2' :src="baseUrl+'/static/businessschool1.png'" mode=""></image>
					<image v-if='item.fileType==1' :src="item.coverUrl" mode=""></image>
					<image v-if='item.fileType==3' :src="item.fileUrl" mode=""></image>
					<view class="margin-left f-grow1">
						<view class="flex justify-between align-center">
							<view class="text-15 text-333">
								{{item.title}}
							</view>
							<view class="color text-xs">
								{{item.price==0?'免费':'收费'}}
							</view>
						</view>
						<view class="text-666 text-sm margin-top-xs">
							{{item.typeName}}
						</view>
						<view class="flex justify-between align-center text-xs text-999 margin-top-sm">
							<view class="">
								{{item.createTime}}
							</view>
							<view class="flex justify-start align-center">
								<view class="" v-if='item.fileType==2'>
									阅读{{item.readNum}}
								</view>
								<view class="margin-left" v-if='item.fileType==2'>
									下载{{item.downNum}}
								</view>
							</view>
						</view>
					</view>
				</view>


				<view class="flex justify-end align-center margin-top" @click.stop="deletePro(item.id)">
					<button class="btn round text-13">删除</button>
				</view>
			</view>
		</block>

		<block v-if='type==2'>
			<view class="margin-sm bg-white padding list radius10" v-for="(item,index) in list" :key='index'>
				<view class="flex justify-start align-center">
					<image :src="item.headImg" mode="" class="image"></image>
					<view class="margin-left f-grow1">
						<view class="flex justify-between align-center">
							<view class="text-15 text-333 font">
								<view>{{item.nickName}}</view>
								<view>{{item.createTime}}</view>
							</view>
							<view class="color text-xs edit" @click="cancel(item.followId)">
								取消关注
							</view>
						</view>

					</view>
				</view>

			</view>
		</block>
		<block v-if='type==3'>
			<view class="margin-sm bg-white padding list radius10" v-for='(item,index) in list' :key='index'>
				<view class="flex justify-start align-center">
					<image :src="item.headImg" mode="" class="image"></image>
					<view class="margin-left f-grow1">
						<view class="flex justify-between align-center">
							<view>
								<view class="text-15 text-333  text-cut" style='width: 440rpx;'>
									{{item.commentMsg}}
								</view>
								<view  class="text-15 text-333  text-cut" style='width: 440rpx;margin-top: 10px;color: #999;'>
									{{item.createTime}}
								</view>
							</view>
							<view class="color text-xs" style="font-size: 14px;">
								{{item.nickName}}
							</view>
						</view>

					</view>
				</view>

			</view>
		</block>
<block v-if='type==4'>
			<view class="margin-sm bg-white padding list radius10" v-for='(item,index) in list' :key='index'>
				<view class="flex justify-between align-center">
							<view class="flex-sub text-cut">
								<view class="text-15 text-333  text-cut" style=''>
									{{item.linkName}}
								</view>
								<view  class="text-15 text-333 text-cut" style='margin-top: 10px;color: #999;'>
									{{item.idCardNo}}
								</view>
							</view>
							<view class="flex-sub">
								<view class="text-15 text-333 text-cut" style=''>
									{{item.phone}}
								</view>
								<view  class="text-15 text-333 text-cut" style='margin-top: 10px;color: #999;'>
									{{item.createTime}}
								</view>
							</view>
							<!-- <view class="flex-sub">
								<view class="text-15 text-333  text-cut" style='width: 440rpx;'>
									{{item.idCardNo}}
								</view>
								<view  class="text-15 text-333  text-cut" style='width: 440rpx;margin-top: 10px;color: #999;'>
									{{item.createTime}}
								</view>
							</view> -->
				</view>

			</view>
		</block>
		<uni-load-more :status="loading" />
	</view>
</template>

<script>
	import BetterPull from '@/common/util/BetterPull'
	export default {
		mixins: [
			BetterPull({
				async getPage(page, done) {
					this.loading = 'loading';
					const obj = {
						userId: uni.getStorageSync('userId'),
						pageNum: page,
						pageSize: 10
					}
					if (this.title) {
						obj['title'] = this.title
					}
					let api = ''
					if (this.type == 1) {
						api = 'myProgramme'
					} else if (this.type == 2) {
						api = 'myFollow'
					} else if (this.type == 3) {
						api = 'myRecomendList'
					}else {
						api = 'signList'
						obj['payStatus'] = 1
					}


					const [err, res] = await this.$get(this.$api[api], obj)
					if (res) {
						var data = res.data.list
						done(data);
						if (data.length < 10) {
							this.loading = 'noMore';
						} else {
							this.loading = 'more';
						}

					}
					if (err) {
						done([]);
						this.loading = 'noMore';
					}
				}
			})
		],
		data() {
			return {
				baseUrl: this.$config.baseUrl,
				loading: "more",
				type: 1,
				title: ''
			};
		},
		methods: {
			handClick(id, type, item) {
				console.log(id, type)
				if (type != 1) {
					this.$util.openNewPage('/filePage/pages/file-detail/file-detail?id=' + id)
				} else {
					this.$util.openNewPage('/pagesA/pages/myVideo/myVideo?id=' + id + '&typeId=' + item.typeId +
						'&typeChildId=' + item.secondTypeId)
				}
			},
			back() {
				console.log(1111)
				uni.navigateBack({

				})
			},
			searchMyPro() {
				this.Refresh()
			},
			checkType(index) {
				this.type = index
				this.list = []
				this.Refresh()
			},
			cancel(id) {
				const that = this
				uni.showModal({
					title: '提示',
					content: '你确定取消关注该用户吗',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							const data = {
								followId: id
							}
							that.$get(that.$api.follow_addOrDel, data).then(res => {
								const [err, rs] = res
								if (rs) {
									that.$util.msg(that.message)
									that.Refresh()
								}
							})

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			deletePro(id) {
				const that = this
				uni.showModal({
					title: '提示',
					content: '你确定删除该数据吗',
					success: function(res) {
						if (res.confirm) {
							that.$get(that.$api.myProDel, {
								programmeId: id,
								type: 1
							}).then(res => {
								const [err, rs] = res
								if (rs) {
									that.$util.msg(that.message)
									that.Refresh()
								}
							})
						}
					}
				})
			}
		},

	}
</script>

<style lang="scss" scoped>
	.tabs {
		view {
			border-bottom: 6rpx solid #fff;
		}

		.on {
			font-weight: bold;
			color: #221815;
			border-bottom: 6rpx solid #ED7200;
		}
	}

	.list {
		image {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.btn {
		color: #FF3636;
		padding: 20rpx 50rpx;
		border: 2rpx solid;
	}

	.searchs {
		width: 74rpx;
		height: 74rpx;
		line-height: 74rpx;
		position: fixed;
		top: 220rpx;
		right: 20rpx;
		z-index: 1;
	}

	.image {
		border-radius: 50%;
	}

	.font {
		font-size: 28rpx;
		color: #999;
	}

	.font>view:first-child {
		margin-bottom: 10rpx;
	}

	.edit {
		background: linear-gradient(90deg, #ff416c, #ff4b2b);
		color: #fff;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
	}

	.status-center {
		width: 460rpx;
		display: flex;
		align-items: center;
	}
</style>
